<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/css/custom-style.css}">
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/4.1.3/css/bootstrap.min.css}">
    <script th:src="@{/webjars/jquery/3.3.1-1/jquery.min.js}"></script>
    <script th:src="@{/webjars/bootstrap/4.1.3/js/bootstrap.min.js}"></script>
</head>
<body>

<header th:fragment="topbar">
    <!-- Fixed navbar -->
    <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
        <a class="navbar-brand" href="#">Go Learn</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarCollapse">
            <ul class="navbar-nav mr-auto">
                <li th:class="${currentPage}=='index'?'nav-item active':'nav-item'" class="nav-item active">
                    <a th:href="@{/}" class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                </li>
            </ul>
            <span th:if="${session.user}==null">
                <a th:href="@{/register}"
                   th:class="${currentPage}=='register'?'btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted active':'btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted'"
                   class="btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted">Register</a>
                <a th:href="@{/login}"
                   th:class="${currentPage}=='login'?'btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted active':'btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted'"
                   class="btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted">Login</a>
            </span>
            <span th:if="${session.user}!=null">

                <a th:class="'btn btn-outline-dark text-white-50 my-2 my-sm-0'"
                   th:href="@{/account}">
                    <img th:src="${session.user.userIcon}==null?@{/img/defaultIcon.png}:@{${session.user.userIcon}}"
                         th:class="'user-small rounded-circle img-fluid align-self-center mr-3'"
                    />
                    <span th:text="${session.user.userName}"></span>
                </a>
                <a th:href="@{/logout}"
                   th:class="'btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted'"
                   class="btn btn-dark my-2 my-sm-0 mr-sm-2 text-muted">Logout</a>
            </span>
            <div class="form-inline mt-2 mt-md-0">
                <input id="searchInput" class="form-control mr-sm-2" placeholder="Search" aria-label="Search" type="text">
                <button id="searchBtn" class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
            </div>
        </div>
    </nav>
    <script>
        $('#searchBtn').click(function () {
            var videoName = $('#searchInput').val();
            $(location).attr("href", "/search/" + videoName);
        });
    </script>
</header>

</body>
</html>